package com.ling.luo.base.producer;


//import org.apache.rocketmq.client.producer.DefaultMQProducer;
//import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;


import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;

/**
 * 发送同步消息
 *
 * @author luohoujian
 * @since 2021/05/25
 */
public class SyncProducer {

    /**
     * 消息发送者步骤分析
     * 1.创建消息生产者producer，并制定生产者组名
     * 2.指定Nameserver地址
     * 3.启动producer
     * 4.创建消息对象，指定主题Topic，Tag和消息体
     * 5.发送消息
     * 6.关闭生产者producer
     */
    public static void main(String[] args) throws Exception {
        // * 1.创建消息生产者producer，并制定生产者组名
        DefaultMQProducer producer = new DefaultMQProducer("group1");
        // * 2.指定Nameserver地址，多个使用;隔开 127.0.0.1:9876;127.0.0.1:9877
        producer.setNamesrvAddr("127.0.0.1:9876");
        // * 3.启动producer
        producer.start();
        // * 4.创建消息对象，指定主题Topic，Tag和消息体
        Message msg = new Message("topic1", "tag1", "hello rocketmq".getBytes());
        // * 5.发送消息
        SendResult result = producer.send(msg);
        System.out.println("消息id" + result.getMsgId() + " , " + result.getSendStatus());
        // * 6.关闭生产者producer
         producer.shutdown();
    }
}
